package com.neuedu.mvc.filter;

import javax.servlet.*;
import javax.servlet.annotation.*;
import java.io.IOException;


//@WebFilter(filterName = "CharsetEncodingFilter", urlPatterns = "/*")
public class CharsetEncodingFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
//        System.out.println("Filter init");

    }

    public void destroy() {
        System.out.println("CharsetEncodingFilter.destroy");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {


//        ServletContext application = request.getServletContext();



//        System.out.println("1 执行 CharsetEncodingFilter 前置的 代码");
        request.setCharacterEncoding("utf-8");
        //放行
        chain.doFilter(request, response);

        response.setCharacterEncoding("utf-8");
//        System.out.println("5 执行 CharsetEncodingFilter 后置 代码");
    }
}
